/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.hiof.bluetooth;

import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

/**
 *
 * @author manish
 */
public class BluetoothConnector {

    Context context;
    public static final int REQUEST_ENABLE_BT = 1;
    BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    public BluetoothConnector(Context context) {
        this.context = context;
    }

    private boolean hasBluetoothSupport() {
        return bluetoothAdapter != null;
    }

    public boolean enableBluetooth() {
        if (!hasBluetoothSupport()) {
            Toast.makeText(context, "Bluetooth not supported in the current device", Toast.LENGTH_SHORT).show();
            return false;
        } else if (!bluetoothAdapter.isEnabled()) {
            Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
            ((Activity) context).startActivityForResult(enableIntent, REQUEST_ENABLE_BT);
            return true;
        }
        Toast.makeText(context, "Bluetooth not Enabled", Toast.LENGTH_SHORT).show();
        return false;
    }
}
